import { onMounted, onBeforeUnmount, onActivated } from "vue";
import { debounce } from "lodash-es";
 
export function useResize(callback: () => void, timeout = 500) {
  const debounceResize = debounce(callback, timeout);
  onMounted(() => {
    window.addEventListener("resize", debounceResize);
  });
 
  onBeforeUnmount(() => {
    window.removeEventListener("resize", debounceResize);
  });
// 进入缓存组件是调用该方法，自适应尺寸
  onActivated(() => {
    callback();
  });
}